package com.lanou.moving.adapter;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.Environment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lanou.moving.R;
import com.lanou.moving.entity.AlbumDetailRoot;
import com.lanou.moving.utils.Exchange;
import com.lanou.moving.view.CommonProgressDialog;

import java.io.File;
import java.util.List;

/**
 * Created by 梁树珍 on 15/11/2.
 */
public class AlbumDetailAdapter extends BaseAdapter {
    private Context context;
    private List<AlbumDetailRoot.DataEntity.SongListEntity> albumList;
    private OnMenuClickListener onMenuClickListener;

    public AlbumDetailAdapter(Context context, List<AlbumDetailRoot.DataEntity.SongListEntity> albumList) {
        this.context = context;
        this.albumList = albumList;
    }

    public interface OnMenuClickListener {
        void onMenuClick(AlbumDetailRoot.DataEntity.SongListEntity songsEntity);
    }

    public void setOnMenuClickListener(OnMenuClickListener onMenuClickListener) {
        this.onMenuClickListener = onMenuClickListener;
    }

    @Override
    public int getCount() {
        return albumList == null ? 0 : albumList.size();
    }

    @Override
    public Object getItem(int position) {
        return albumList == null ? null : albumList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.songs_list_listview_item, null);
            holder = new ViewHolder();
            holder.songs_list_position = (TextView) convertView.findViewById(R.id.songs_list_position);
            holder.songs_list_songName = (TextView) convertView.findViewById(R.id.songs_list_songName);
            holder.songs_list_item_singer = (TextView) convertView.findViewById(R.id.songs_list_item_singer);
            holder.songs_list_item_number = (TextView) convertView.findViewById(R.id.songs_list_item_number);
            holder.list_more = (ImageView) convertView.findViewById(R.id.list_more);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        final AlbumDetailRoot.DataEntity.SongListEntity dataEntity = (AlbumDetailRoot.DataEntity.SongListEntity) getItem(position);
        String num = Exchange.getCount(albumList.get(position).getFavorites());
        holder.songs_list_position.setText(position + 1 + "");
        holder.songs_list_songName.setText(albumList.get(position).getName());
        holder.songs_list_item_singer.setText(albumList.get(position).getSingerName());
        holder.songs_list_item_number.setText(num);
        holder.list_more.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onMenuClickListener != null) {
                    onMenuClickListener.onMenuClick(albumList.get(position));
                }
            }
        });

        return convertView;
    }

    private class ViewHolder {
        private ImageView list_more;
        private TextView songs_list_position;
        private TextView songs_list_songName;
        private TextView songs_list_item_singer;
        private TextView songs_list_item_number;

    }
}
